package com.heima.sjms.单例模式.懒汉式;

import com.heima.sjms.单例模式.Student;

import java.lang.reflect.Constructor;

/**
 * @author 陈辉
 * @data 2023 14:03
 */

public class Demo {
    private static Student stu;

    public static void main(String[] args) {
        Student stu1 = getStu();
        Student stu2 = getStu();

        System.out.println(stu1 == stu2);
    }

    public static Student getStu(){
        if (stu == null){
            try {
                Class<Student> studentClass = Student.class;
                Constructor<Student> constructor = studentClass.getDeclaredConstructor();
                constructor.setAccessible(true);
                stu = constructor.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return stu;
    }


}
